<script setup lang="ts">
import { PAGINATIONFOOT } from "@/utils/staticData";
import router from "@/router";
import { allocationTypeList } from "@/utils/staticData";
import { add } from "@/utils/caculate";

defineOptions({ name: "manageTable" });
defineProps({
  tableHeight: { default: 0, type: Number },
  tableData: { type: Array, default: () => [] },
  pagination: { type: Object, default: () => {} }
});

const handleDetail = (row: any) => {
  router.push({
    path: "/inventory/inventoryTransferPage",
    query: { id: row.id }
  });
};

const goTransferConfirm = (row: any) => {
  router.push({
    path: "/inventory/inventoryTransferConfirmDetail",
    query: { id: row.id }
  });
};
</script>

<template>
  <el-table
    :data="tableData"
    class="tableBox"
    style="width: 100%"
    :height="
      tableHeight - (pagination.total > pagination.size ? PAGINATIONFOOT : 0)
    "
  >
    <el-table-column type="index" label="序号" min-width="88px" />
    <el-table-column
      prop="allocationCode"
      label="调拨单据编号"
      min-width="184px"
      show-overflow-tooltip
    />
    <el-table-column
      prop="allocationType"
      label="调拨类型"
      min-width="136px"
      show-overflow-tooltip
    >
      <template #default="{ row }">
        {{
          allocationTypeList.find(item => item.value === row.allocationType)
            ?.label
        }}
      </template>
    </el-table-column>
    <el-table-column
      prop="originWarehouseName"
      label="调出仓库"
      min-width="152px"
      show-overflow-tooltip
    />
    <el-table-column
      prop="outboundNum"
      label="调出总数"
      min-width="104px"
      show-overflow-tooltip
    />
    <el-table-column
      prop="applicantName"
      label="调拨出库人"
      min-width="120px"
      show-overflow-tooltip
    />
    <el-table-column
      prop="targetWarehouseName"
      label="调入仓库"
      min-width="152px"
      show-overflow-tooltip
    />
    <el-table-column
      prop="inboundNum"
      label="调入总数"
      min-width="104px"
      show-overflow-tooltip
    />
    <el-table-column
      prop="diffNum"
      label="差额处理总数"
      min-width="136px"
      show-overflow-tooltip
    />
    <el-table-column
      prop="createTime"
      label="创建时间"
      min-width="200px"
      show-overflow-tooltip
    />
    <el-table-column fixed="right" label="操作" align="left" min-width="125px">
      <template #default="{ row }">
        <el-button
          v-if="add(row.diffNum, row.inboundNum) !== row.outboundNum"
          type="primary"
          link
          @click="goTransferConfirm(row)"
          >入库</el-button
        >
        <el-button type="primary" link @click="handleDetail(row)"
          >详情</el-button
        >
      </template>
    </el-table-column>
  </el-table>
</template>
